﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1.SessionDemo
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["goods"] = new List<string>();
            }
            if (Session["currentUser"] == null)
            {
                Literal1.Text = "您还没有登录，请登录！";
            }
            else
            {
                Literal1.Text = "欢迎您：" + Session["currentUser"] + " !";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Session["currentUser"] == null)
            {
                Response.Redirect("WebForm3.aspx");
            }
            else
            {
                List<string> list = (List<string>)Session["goods"];
                foreach (Control item in form1.Controls)
                {
                    if (item is CheckBox)
                    {
                        CheckBox cb = (CheckBox)item;
                        if (cb.Checked)
                        {
                            list.Add(cb.Text); ;
                        }
                    }
                }
                Button1.Text = "添加成功！";
                Response.Write(Session.SessionID);
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("WebForm2.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Literal1.Text = "您还没有登录，请登录！";
        }
    }
}